package com.crr.controller;

import com.crr.bean.PageResult;
import com.crr.bean.ResultBean;
import com.crr.bean.Spu;
import com.crr.query.SpuQuery;
import com.crr.service.SpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.Map;
@CrossOrigin
@RestController
@Api(tags = "商品接口")
@RequestMapping("/api/spu")
public class SpuController extends BaseController {


    @Autowired
    SpuService spuService;

    @ApiOperation("新增商品")
    @PostMapping("/save")
    public ResultBean save(@RequestBody Spu spu) {
        int res = spuService.saveSpu(spu);
        return saveResult(res);
    }

    @PostMapping("/query")
    @ApiOperation("查询全部")
    public ResultBean query(@RequestBody SpuQuery query) {
        PageResult<Spu> result = spuService.query(query);
        return success("商品列表", result);
    }
    @GetMapping("/get")
    @ApiOperation("根据id查询全部详情")
    public ResultBean getDetail(@RequestParam(value = "id",required = true) int id) {
        Map detail = spuService.getDetail(id);
        return success("商品列表", detail);
    }
}
